package com.erlinyou.im.web.controller.notice.impl;

import java.util.List;
import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.erlinyou.base.service.BaseServiceImpl;
import com.erlinyou.im.dao.repository.notice.ChatNotifiedRepository;
import com.erlinyou.im.dao.repository.offline.OfflineMessageRepository;
import com.erlinyou.im.model.notified.ChatNotified;
import com.erlinyou.im.model.offline.OfflineMessage;
import com.erlinyou.im.web.controller.notice.ChatNotifiedService;
@Service
public class ChatNotifiedServiceImpl extends BaseServiceImpl<ChatNotified, String> implements ChatNotifiedService {

	@Resource
	private ChatNotifiedRepository repository;
	@Resource
	private OfflineMessageRepository offlineMessageRepository;

	@Override
	public <S extends ChatNotified> S save(S entity) {
		return repository.save(entity);
	}

	
	@Override
	public boolean saveOffAndNotified(ChatNotified chatNotified,OfflineMessage offlineMessage) {
		boolean b = repository.save(chatNotified)!=null;
		if(b) {
			boolean b1 = offlineMessageRepository.save(offlineMessage)!=null;
			if(b1) {
				return true;
			}else {
				throw new RuntimeException();
			}
		}else {
			throw new RuntimeException();
		}
	}
	
	@Override
	public void deleteById(String id) {
		baseRepository.deleteById(id);
	}


	@Override
	public List<ChatNotified> findByUserid(Long userid) {
		return repository.findByUserid(userid);
	}
	
	@Override
	public ChatNotified findByUseridAndMsgId(Long userid,String msgId){
		return repository.findByUseridAndMsgId(userid,msgId);
	}

}
